
export const menudata = [
    {
        title: '承建商管理',
        key: '0-0',
        directive: 'sub1',
        children: [
            {
                title: '承建商登记',
                key: '0-0-0',
                keyvalue: '1',
                click: "/mpage/dengji"
                // path: '/mpage/dengji'
            },
            {
                title: '班组管理',
                key: '0-0-1',
                keyvalue: '2',
                click: "/mpage/classmange"
                // path: "/mpage/classmange"
            },
            {
                title: '用户账号',
                key: '0-0-2',
                keyvalue: '3',
                click: "/mpage/zhanghao"
                // path: "/mpage/zhanghao"
            },
        ],
    },
    {
        title: '花名册管理',
        key: '1-0',
        directive: 'sub2',
        children: [
            {
                title: '花名册登记',
                key: '1-0-0',
                keyvalue: '5',
                click: "/mpage/flower"
                // path: "/mpage/changeflo"
            },
            {
                title: '黑白名单管理',
                key: '1-0-1',
                keyvalue: '6',
                click: "/mpage/blackwhite"
                // path: "/mpage/changebla"
            },
            {
                title: '黑白名单通行',
                key: '1-0-2',
                keyvalue: '7-',
                click: "/mpage/black"
                // path: "/mpage/changeblack"
            },
        ],
    },
    {
        title: '考勤管理',
        key: '2-0',
        directive: 'sub3',
        children: [
            {
                title: '考勤组管理',
                key: '2-0-0',
                keyvalue: '9',
                click: "/mpage/kaoqin"
                // path: "/mpage/kaoqin"
            },
            {
                title: '考勤规则',
                key: '2-0-1',
                keyvalue: '10',
                click: "/mpage/guize"
                // path: "/mpage/guize"
            },
            {
                title: '考勤记录',
                key: '2-0-2',
                keyvalue: '11',
                click: "/mpage/jilu"
                // path: "/mpage/jilu"
            },
            {
                title: '考勤统计',
                key: '2-0-3',
                keyvalue: '12',
            },
        ],
    },
    {
        title: '项目配置',
        key: '3-0',
        directive: 'sub4',
        children: [
            {
                title: '项目管理',
                key: '3-0-0',
                keyvalue: '14',
                click: "/mpage/pmanage"
                // path: "/mpage/pmanage"
            },
            {
                title: '设备管理',
                key: '3-0-1',
                keyvalue: '15',
                click: "/mpage/emanage"
                // path: "/mpage/emanage"
            }
        ],
    },
    {
        title: '基本设置',
        key: '4-0',
        directive: 'sub5',
        children: [
            {
                title: '账号管理',
                key: '4-0-0',
                keyvalue: '17',
                click: "/mpage/zhanghao1"
                // path: "/mpage/zhaohao1"
            },
            {
                title: '角色权限',
                key: '4-0-1',
                keyvalue: '18',
                click: "/mpage/quanxian"
                // path: "/mpage/quanxian"
            },
            {
                title: '工种字典',
                key: '4-0-2',
                keyvalue: '19',
                click: "/mpage/zidian"
                // path: "/mpage/zidian"
            }
        ],
    }
];
// 根据当前用户的权限,产生相应的菜单

export default function getMenus() {
    // 1.获取该用户的权限
    let checkedkeys: string[] = [];
    let currkeys = sessionStorage.getItem("grants");


    if (currkeys) {
        checkedkeys = JSON.parse(currkeys)
        console.log(currkeys);
    }
    if (checkedkeys.length === 0) {
        checkedkeys = ['0-0', '0-0-0', '0-0-1', '0-0-2', '1-0', '1-0-0', '1-0-1', '1-0-2', '2-0', '2-0-0', '2-0-1', '2-0-2', '2-0-3', '3-0', '3-0-0', '3-0-1', '4-0', '4-0-0', '4-0-1', '4-0-2'];
    }

    // 获取该用户的权限结合全部菜单数据,产生该用户的菜单

    interface IMenuItem {
        key: string,
        title: string,
        path?: string,
        children?: IMenuItem[]
    }
    let currMenuData: IMenuItem[] = [];//存储当前用户菜单项
    menudata.forEach(item => {
        if (checkedkeys.indexOf(item.key) > -1) {
            //定义一个菜单项;
            const newmenuItem = { ...item };
            //处理子一级
            if (item.children) {
                newmenuItem.children = [];
                item.children.forEach(sonItem => {
                    if (checkedkeys.indexOf(sonItem.key) > -1) {
                        newmenuItem.children?.push({ ...sonItem });
                    }
                })
            }
            currMenuData.push(newmenuItem)
        }

    });
    console.log("currMenuData", currMenuData);

    return currMenuData;
}
